
#include <stdio.h>

#include "assembler_parser.h"
#include "command.h"
#include "interpreter.h"

#include "interpreter_facade.h"

namespace assembler {

void InterpreterFacade::ParseAndInterpret(MachineState *state,
                                          const char *commands) {
  Interpreter interpreter(state);
  Lexer lexer(commands, strlen(commands));
  Parser parser(&lexer);
  while (parser.ConsumeCommand()) {
    const Command &command = parser.cmd();
    if (!command.is_valid()) {
      fprintf(stderr, "Interpreter found invalid command, stopping "
        "interpretation process\n");
      break;
    }
    interpreter.Interpret(command);
  }
  if (!parser.is_valid()) {
    fprintf(stderr, "Parser brought an invalid lexeme sequence\n");
  }
}

}  // namespace assembler